;;; init-vc.el --- Version control settings -*- lexical-binding: t -*-
;;; Commentary:

;;; Code:

;; 基于文本的 git GUI
(use-package magit
  :ensure t
  :commands (magit magit-status)
  :init
  (setq async-bytecomp-allowed-packages nil) ; 避免magit报错
  :custom
  (magit-diff-refine-hunk t)
  (magit-ediff-dwim-show-on-hunks t))

;; 借助 git-delta 美化 magit 内的 git diff
(use-package magit-delta
  :ensure t
  :hook (magit-mode . magit-delta-mode)
  :config
  (setq magit-delta-hide-plus-minus-markers nil))

;; 在 fringe 提示哪些文本内容相较于 git 仓库存在变更
;; From: github.com/seagle0128/.emacs.d/blob/master/lisp/init-highlight.el#L250
(use-package diff-hl
  :when (display-graphic-p)
  :ensure t
  :hook (elpaca-after-init . global-diff-hl-mode)
  :custom-face
  (diff-hl-change ((t (:foreground "#339CDB" :background unspecified))))
  (diff-hl-insert ((t (:foreground "#579C4C" :background unspecified))))
  (diff-hl-delete ((t (:foreground "#D16969" :background unspecified))))
  :custom
  (diff-hl-draw-borders nil)
  (diff-hl-show-hunk-function 'diff-hl-show-hunk-posframe)
  :config    
  ;; Highlight on-the-fly([计] 及时)
  (when (not (eq system-type 'windows-nt))
    (global-diff-hl-show-hunk-mouse-mode 1)
    (diff-hl-flydiff-mode 1))

  ;; Integration with magit
  (with-eval-after-load 'magit
    (add-hook 'magit-pre-refresh-hook #'diff-hl-magit-pre-refresh)
    (add-hook 'magit-post-refresh-hook #'diff-hl-magit-post-refresh))

  ;; custom bitmap of diff-hl
  (setq diff-hl-fringe-bmp-function
        (lambda (_type _pos)
          (define-fringe-bitmap
            'my-diff-hl-bmp
            (vector (if (eq system-type 'windows-nt)
                        #b11111100
                      #b11100000))
            1 8
            '(center repeated)))))

(provide 'init-vc)
;;; init-vc.el ends here
